<!DOCTYPE HTML>
<html lang="zh-hans" >
    <!-- Start book Python基础 -->
<!-- Start book Python基础 -->
    <head>
        <!-- head:start -->
<!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>条件判断语句补充 | Python基础</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="姜伟">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../chapter02.html" />
    
    
    <link rel="prev" href="section05.html" />
    

        <!-- head:end -->
<!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
<!-- body:start -->
        
    <div class="book"
        data-level="1.6"
        data-chapter-title="条件判断语句补充"
        data-filepath="01/section06.md"
        data-basepath=".."
        data-revision="Mon Feb 03 2020 14:44:53 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter01.html">
            
                
                    <a href="../chapter01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        条件判断语句
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="01/section01.html">
            
                
                    <a href="section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        if语句的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01/section02.html">
            
                
                    <a href="section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        if...else语句的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="01/section03.html">
            
                
                    <a href="section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        if...elif...else语句的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="01/section04.html">
            
                
                    <a href="section04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        if语句嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="01/section05.html">
            
                
                    <a href="section05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        条件判断练习:猜拳游戏
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="01/section06.html">
            
                
                    <a href="../01/section06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        条件判断语句补充
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter02.html">
            
                
                    <a href="../chapter02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        循环语句
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="02/section01.html">
            
                
                    <a href="../02/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        while语句的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="02/section02.html">
            
                
                    <a href="../02/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        for语句的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="02/section03.html">
            
                
                    <a href="../02/section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        break和continue的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="02/section04.html">
            
                
                    <a href="../02/section04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        嵌套循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="02/section05.html">
            
                
                    <a href="../02/section05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        for...else语句的使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本书使用 GitBook 发布
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Python基础</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h2 id="if&#x8865;&#x5145;&#x5185;&#x5BB9;">if&#x8865;&#x5145;&#x5185;&#x5BB9;</h2>
<h3 id="&#x4E00;&#x3001;&#x533A;&#x95F4;&#x6BD4;&#x8F83;">&#x4E00;&#x3001;&#x533A;&#x95F4;&#x6BD4;&#x8F83;:</h3>
<p>&#x5728;Python&#x4E2D;&#x5141;&#x8BB8;&#x7C7B;&#x4F3C;&#x4E8E; <code>5&lt;a&lt;10</code> &#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x5728;&#x5F88;&#x591A;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x91CC;&#x90FD;&#x662F;&#x4E0D;&#x5141;&#x8BB8;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x903B;&#x8F91;&#x4E0E;&#x8FD0;&#x7B97;&#x7B26;&#x8FDB;&#x884C;&#x8FDE;&#x63A5;&#x3002;</p>
<pre><code class="lang-python">a = <span class="hljs-number">10</span>
<span class="hljs-number">1</span>&lt;a&lt;<span class="hljs-number">20</span>  <span class="hljs-comment"># True</span>
<span class="hljs-number">11</span>&lt;a&lt;<span class="hljs-number">20</span>  <span class="hljs-comment"># False</span>
</code></pre>
<h3 id="&#x4E8C;&#x3001;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;">&#x4E8C;&#x3001;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;:</h3>
<p>&#x683C;&#x5F0F;&#xFF1A;
<code>&#x53D8;&#x91CF; = &#x503C;1 if &#x6761;&#x4EF6; else &#x503C;2</code>
&#x5F53;&#x6761;&#x4EF6;&#x6210;&#x7ACB;&#x65F6;&#x628A; &#x503C;1 &#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#xFF0C;&#x6761;&#x4EF6;&#x4E0D;&#x6210;&#x7ACB;&#x65F6;&#x628A; &#x503C;2 &#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x5BF9;if...else &#x8BED;&#x53E5;&#x7684;&#x4E00;&#x79CD;&#x7B80;&#x5199;&#x3002;</p>
<p>&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-python">a = <span class="hljs-number">10</span>
b = <span class="hljs-number">30</span>
<span class="hljs-keyword">if</span> a &gt; b:
    c = a
<span class="hljs-keyword">else</span>:
    c = b
print(<span class="hljs-string">&apos;a&#x548C;b&#x4E24;&#x4E2A;&#x6570;&#x7684;&#x8F83;&#x5927;&#x503C;&#x662F;%d&apos;</span>%c)
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x7684; <code>if...else</code> &#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x7B80;&#x5199;&#x6210;&#x4EE5;&#x4E0B;&#x683C;&#x5F0F;:</p>
<pre><code class="lang-python">a = <span class="hljs-number">10</span>
b = <span class="hljs-number">30</span>
c = a <span class="hljs-keyword">if</span> a&gt;b <span class="hljs-keyword">else</span> b
print(<span class="hljs-string">&apos;a&#x548C;b&#x4E24;&#x4E2A;&#x6570;&#x7684;&#x8F83;&#x5927;&#x503C;&#x662F;%d&apos;</span>%c)
</code></pre>
<h3 id="&#x4E09;&#x3001;&#x81EA;&#x52A8;&#x7C7B;&#x578B;&#x8F6C;&#x6362;">&#x4E09;&#x3001;&#x81EA;&#x52A8;&#x7C7B;&#x578B;&#x8F6C;&#x6362;</h3>
<p>if &#x8BED;&#x53E5;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#xFF0C;&#x8FD9;&#x4E2A;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x7684;&#x7ED3;&#x679C;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#x3002;&#x5982;&#x679C;&#x6B64;&#x65F6;&#x8F93;&#x5165;&#x7684;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x5728;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x4F1A;&#x5C06;&#x8FD9;&#x4E2A;&#x503C;&#x81EA;&#x52A8;&#x8F6C;&#x6362;&#x6210;&#x4E3A;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> <span class="hljs-number">1</span>&lt;<span class="hljs-number">2</span>: <span class="hljs-comment"># if&#x8BED;&#x53E5;&#x7684;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;</span>
    print(<span class="hljs-string">&apos;1&#x5C0F;&#x4E8E;2&apos;</span>)

<span class="hljs-keyword">if</span> <span class="hljs-string">&quot;hello&quot;</span>: <span class="hljs-comment"># if &#x5224;&#x65AD;&#x6761;&#x4EF6;&#x540E;&#x6CA1;&#x6709;&#x4F20;&#x5165;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x628A;&#x5B83;&#x8F6C;&#x6362;&#x6210;&#x4E3A;&#x5E03;&#x5C14;&#x503C;</span>
    print(<span class="hljs-string">&quot;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x662F;&#x5426;&#x4F1A;&#x8F93;&#x51FA;&#x5462;&#xFF1F;&quot;</span>)
</code></pre>
<p>&#x63D0;&#x793A;&#xFF1A;&#x5728;Python&#x4E2D;&#xFF0C;&#x8F6C;&#x6362;&#x6210;&#x4E3A;&#x5E03;&#x5C14;&#x503C;&#x65F6;&#xFF0C;&#x53EA;&#x6709; <span style="color:red"><code>0,&quot;&quot;,&apos;&apos;,None,(),{},[]</code></span> &#x4F1A;&#x88AB;&#x8F6C;&#x6362;&#x6210;&#x4E3A;False,&#x5176;&#x4ED6;&#x90FD;&#x4F1A;&#x88AB;&#x8F6C;&#x6362;&#x6210;&#x4E3A;True</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="section05.html" class="navigation navigation-prev " aria-label="Previous page: 条件判断练习:猜拳游戏"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter02.html" class="navigation navigation-next " aria-label="Next page: 循环语句"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-copy-code-button/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"prism":{},"splitter":{},"copy-code-button":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
<!-- body:end -->
    </body>
    <!-- End of book Python基础 -->
<!-- End of book Python基础 -->
</html>
